#pragma once

#include <QtCore>
#include <QtGui>
#include <QtOpenGL>
#include "abstractrenderhandler.h"

class GearRenderHandler : public AbstractRenderHandler
{
public:
	GearRenderHandler(QGLWidget *parent);

    void initializeGL();	
    void paintGL();
	void resizeGL(int width, int height);
	void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
	void renderLoop();
		
	int xRotation() const { return xRot; }
    int yRotation() const { return yRot; }
    int zRotation() const { return zRot; }

public:
    void setXRotation(int angle);
    void setYRotation(int angle);
    void setZRotation(int angle);

private:
	GLuint makeGear(const GLfloat *reflectance, GLdouble innerRadius,
                    GLdouble outerRadius, GLdouble thickness,
                    GLdouble toothSize, GLint toothCount);
	void drawGear(GLuint gear, GLdouble dx, GLdouble dy, GLdouble dz,
                  GLdouble angle);
	void normalizeAngle(int *angle);

private:
	GLuint gear1;
    GLuint gear2;
    GLuint gear3;
    int xRot;
    int yRot;
    int zRot;
    int gear1Rot;
    
    QPoint lastPos;
};